package khh;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.RoundEndedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that Kylan moves around the walls without coming off of a wall.
 * 
 * @author Kylan Hughes
 * @version 1.0
 * 
 */
public class TestKylanMovement extends RobotTestBed {
  /** True if the robot stayed on the walls the whole time. */
  boolean onWalls = true;
  /** True when the robot reaches the wall from its initial starting place. */
  boolean isOnWalls = false;

  /**
   * Specifies that SittingDuck and Kylan are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,khh.Kylan";
  }

  /**
   * This test runs for 10 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if on wall hasn't come off of a wall.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xPos = robot.getX();
    double yPos = robot.getY();
    if (isOnWalls) {
      if ((xPos > 50) && (xPos < width - 50) && (yPos > 50) && (yPos < height - 50)) {
        onWalls = false;
      }
    }
    else {
      if ((xPos < 30) || (xPos > width - 30) || (yPos < 30) || (yPos > height - 30)) {
        isOnWalls = true;
      }
    }
  }

  /**
   * Need to reset variable after each round or else will throw assertion violation.
   * @param e contains information about the end of the round.
   */
  @Override
  public void onRoundEnded(RoundEndedEvent e) {
    isOnWalls = false;
  }
  /**
   * After the battle, check to see that hasn't come off walls.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check onWalls", onWalls);
  }
}
